package com.link.base.base.youtu.controller;

import com.link.base.base.youtu.model.App;
import com.link.base.base.youtu.service.AppService;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.KeyGenerateService;
import com.link.core.basic.service.ServiceException;
import com.link.core.cllog.LCLogger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * 应用控制器
 * @author 郭闪
 * @date 2018-11-05
 */
@Controller
@RequestMapping("/link/app")
public class AppController extends BasicController<App> {

    @Resource
    private KeyGenerateService keyGenerateService;

    @Resource
    private AppService appService;

    @Override
    public BasicService<App> getBasicService() throws Exception {
        return appService;
    }

    /**
     * 使app生效
     *
     */
    @RequestMapping(value = "/effectApp")
    @ResponseBody
    public Map<String,Object> effectApp(HttpServletRequest request, HttpServletResponse response,App app) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            Long recordId = app.getId();
            if (recordId == null) {
                throw new ServiceException("PUBLIC-007");
            }
            appService.effectApp(app);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }

}
